package org.hhchat.leetcode.dp;

/**
 * Created by HMH on 2017/3/31.
 * dp
 */
public class code303 {
    public static class NumArray {

        private int[] nums;
        public NumArray(int[] nums) {
            for(int i = 1; i < nums.length; i++)
                nums[i] += nums[i - 1];
            this.nums = nums;
        }

        public int sumRange(int i, int j) {
            if(i == 0)
                return nums[j];

            return nums[j] - nums[i - 1];
        }
    }

    public static void main(String[] args){
        int nums[] = new int[]{-2, 0, 3, -5, 2, -1};
        NumArray array = new NumArray(nums);
        System.out.println(array.sumRange(0, 5));
    }
}
